package com.qidianit.mes.md.controller;

import com.qidianit.common.pojo.MESResult;
import com.qidianit.mes.md.service.BOMService;
import com.qidianit.mes.md.vo.MaterialBomVO;
import com.qidianit.mes.pojo.BOM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 奇幻夜之梦
 * @Company 起点编程
 * @Description
 * @Time 2024/10/22 18:28
 */
@RestController
@CrossOrigin
@RequestMapping("/material")
public class BOMController {
    @Autowired
    private BOMService bomService;
    @GetMapping("/listBOM")
    public MESResult selectByPage(Long materialId,
                                     @RequestParam(defaultValue = "1")int page,
                                     @RequestParam(defaultValue = "10")int limit){
        // 这里只有一行代码，直接调用service，不处理任何业务
        return bomService.selectByPage(materialId,page,limit);
    }

    @PostMapping("/saveBOM")
    public MESResult save(@RequestBody MaterialBomVO vo) {
        return  bomService.save(vo.getMaterialOfId(),vo.getMaterialIds());
    }

    @PutMapping("/updateBOM")
    public MESResult update(@RequestBody BOM bom) {
        return bomService.updateBom(bom);
    }

    @GetMapping("selectBOMById")
    public MESResult selectById(Long bomId) {
        return bomService.selectById(bomId);
    }

    @DeleteMapping("/deleteBOM")
    public MESResult delete(Long bomId){
        return bomService.delete(bomId);
    }

    @DeleteMapping("/deleteBOMs")
    public MESResult deletes(String [] bomId){
        return bomService.deletes(bomId);
    }
}

